<template>
	<view class="boxList comment">
		<view class="commentItem" v-for="(item,index) in dataList" :key="index">
			<view class="flex_r_between">
				<view class="userName">{{item.nickname}}</view>
				<view class="NumLikes flex_item_center" @click="likeComment(item.comment_id,index)">
					<image v-if="item.liked===0" style="width: 24rpx;height: 22rpx;margin-right: 10rpx;" src="../../../static/homeImg/icon/dz1.png"
					 mode=""></image>
					 <image v-if="item.liked===1" style="width: 24rpx;height: 22rpx;margin-right: 10rpx;" src="../../../static/homeImg/icon/dz2.png"
					  mode=""></image>{{item.like_count}}
				</view>
			</view>
			<view class="content" @click="$linkTo('./comment_add?comment_id='+item.comment_id)">{{item.content}}</view>
			<view class="oprtu" v-for="(item1,index1) in item.reply_comment" :key="index1">
				<view class="mt">{{item1.nickname}}</view>
				<view class="nptu">{{item1.content}}</view>
				<!-- <view class="nptu"  @click="$linkTo('./comment_add?comment_id='+item1.comment_id)">{{item1.content}}</view> -->
			</view>
		</view>
		<view style="text-align: center;height: 254rpx;padding-top: 30rpx;" class="">
			<image class="logo" src="../../../static/homeImg/icon/feimao.png" mode=""></image>
		</view>
		<view class="pl1 flex_r_center" @click="$linkTo('./comment_add')">
			<image style="height: 40rpx;width: 40rpx;margin-right: 10rpx;" src="../../../static/homeImg/icon/pl1.png" mode=""></image>我要评论
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				article_id:'',
				page:1,
				dataList:[]
			};
		},
		onShow() {
			this.$request('/app/article/getComments','post',{
				article_id:this.article_id,
				comment_id:0,
				page:this.page
			}).then(res=>{
				console.log(res)
				this.dataList=res.content
			})
		},
		methods:{
			likeComment(comment_id,index){
				this.$request('/app/article/likeComment','post',{
					access_token: uni.getStorageSync('access_token').replace(/^\"|\"$/g,''),
					comment_id:comment_id
				}).then(res=>{
					if(res.message==="点赞成功"){
						this.dataList[index].liked=1
					}
					if(res.message==="取消点赞成功"){
						this.dataList[index].liked=0
					}
					console.log(this.dataList.comments)
					this.$set(this.dataList,index,this.dataList[index])
					uni.showToast({
						title:res.message,
						duration:2000,
						icon:'none'
					})
				})
			},
		},
		onLoad(option){
			this.article_id=option.article_id
		}
	}
</script>

<style lang="scss" scoped>
	@import url("@/static/css/flex.css");
	.boxList {
		width: 100%;
		height: auto;
		padding: 0 30rpx;
		box-sizing: border-box;
	}
	.logo{
		width: 280rpx;
		height: 30rpx;
	}
	.pl1{
		width: 690rpx;
		height: 70rpx;
		background: #DB1B22;
		border-radius: 36rpx;
		position: fixed;
		bottom: 14rpx;
		left: 50%;
		transform: translateX(-50%);
		font-size: 28rpx;
		font-family: PingFangSC-Semibold, PingFang SC;
		font-weight: 600;
		color: #FFFFFF;
		line-height: 70rpx;
	}
	.comment {
		.headerO {
			width: 100%;
			height: auto;
			padding: 30rpx 0;
	
			.q {
				font-size: 32rpx;
				font-family: PingFangSC-Medium, PingFang SC;
				font-weight: 500;
				color: #333333;
	
			}
	
			.w {
				font-size: 20rpx;
				font-family: PingFangSC-Semibold, PingFang SC;
				font-weight: 600;
				color: #333333;
	
				image {
					width: 24rpx;
					height: 24rpx;
				}
			}
		}
	
		.commentItem {
			padding: 30rpx 0 20rpx;
			border-bottom: 1px solid #DDDDDD;
			.userName {
				font-size: 24rpx;
				font-family: PingFangSC-Semibold, PingFang SC;
				font-weight: 600;
				color: #333333;
	
			}
	
			.NumLikes {
				font-size: 18rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #777777;
	
			}
	
			.content {
				font-size: 28rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #333333;
				margin: 20rpx 0;
			}
	
			.oprtu {
				width: 690rpx;
				height: 152rpx;
				background: #F6F7F8;
				border-radius: 10rpx;
				padding: 20rpx;
				box-sizing: border-box;
				margin-bottom: 20rpx;
				.mt {
					font-size: 24rpx;
					font-family: PingFangSC-Semibold, PingFang SC;
					font-weight: 600;
					color: #777777;
	
				}
	
				.nptu {
					font-size: 24rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #333333;
					margin-top: 10rpx;
				}
			}
		}
	}
</style>
